package reader.module.fileview;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;

public class FileCanvas extends Canvas implements CommandListener {
	private FileView view = new FileView(getWidth(), getHeight());
	private Command cmdBack = new Command("Back", Command.BACK, 1);

	public FileCanvas() {
		addCommand(cmdBack);
		setCommandListener(this);
	}

	public void paint(Graphics g) {
		g.setColor(0xFFFFFF);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(0x000000);

		view.draw(g);
	}

	public void commandAction(Command cmd, Displayable displayable) {
		if (cmd == cmdBack) {
			view.back();
			repaint();
		}
	}

	public void keyPressed(int keyCode) {
		int action = getGameAction(keyCode);
		switch (action) {
		case UP:
			view.index--;
			break;
		case DOWN:
			view.index++;
			break;
		case FIRE:
			view.select();
			break;
		default:
			break;
		}
		repaint();
	}

}
